<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\ZoneService;
use Illuminate\Http\Request;

class ZoneController extends Controller
{
    private $zoneService;
    public function __construct(ZoneService $zoneService)
    {
        $this->zoneService = $zoneService;
    }
    public function zoneList(Request $request)
    {
        $params = $request->input();
        $result = $this->zoneService->zoneList($params);
        return $this->responseSuccess($result);
    }


    public function zoneAdd(Request $request)
    {
        $params = $request->input();
        if(isset($params['id']) && !empty($params['id'])){
            $result = $this->zoneService->updateZone($params);
            if($result)
                return $this->responseSuccess($result);
            else
                return $this->responseError("更新失败，请重试！");
        }else{
            $result = $this->zoneService->insertZone($params);
            if($result)
                return $this->responseSuccess($result);
            else
                return $this->responseError("新增失败，请重试！");
        }
    }

    public function zoneDel(Request $request)
    {
        $params = $request->input();
        $result = $this->zoneService->zoneDel($params);
        if($result)
            return $this->responseSuccess($result);
        else
            return $this->responseError(400);
    }

    public function zoneStatusChange(Request $request)
    {
        $params = $request->input();
        $result = $this->zoneService->zoneStatusChange($params);
        if($result)
            return $this->responseSuccess($result);
        else
            return $this->responseError(400);
    }
}
